package org.farng.mp3.object;

/**
 * Title: Description: Copyright:    Copyright (c) 2002 Company:
 *
 * @author Eric Farng
 * @version $Revision: 1.9 $
 */
public class ObjectLyrics3Image extends AbstractMP3Object {
    /** DOCUMENT ME! */
    private ObjectLyrics3TimeStamp time = null;

    /** DOCUMENT ME! */
    private String description = "";

    /** DOCUMENT ME! */
    private String filename = "";

    /**
     * Creates a new ObjectLyrics3Image object.
     *
     * @param identifier DOCUMENT ME!
     */
    public ObjectLyrics3Image(String identifier) {
        this.identifier = identifier;
    }

    public ObjectLyrics3Image(ObjectLyrics3Image copyObject) {
        super(copyObject);
        this.time        = new ObjectLyrics3TimeStamp(copyObject.time);
        this.description = new String(copyObject.description);
        this.filename    = new String(copyObject.filename);
    }

    /**
     * DOCUMENT ME!
     *
     * @param description DOCUMENT ME!
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getDescription() {
        return this.description;
    }

    /**
     * DOCUMENT ME!
     *
     * @param filename DOCUMENT ME!
     */
    public void setFilename(String filename) {
        this.filename = filename;
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getFilename() {
        return this.filename;
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public int getSize() {
        int size;

        size = filename.length() + 2 + description.length() + 2;

        if (time != null) {
            size += time.getSize();
        }

        return size;
    }

    /**
     * DOCUMENT ME!
     *
     * @param time DOCUMENT ME!
     */
    public void setTimeStamp(ObjectLyrics3TimeStamp time) {
        this.time = time;
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public ObjectLyrics3TimeStamp getTimeStamp() {
        return this.time;
    }

    /**
     * DOCUMENT ME!
     *
     * @param obj DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public boolean equals(Object obj) {
        if ((obj instanceof ObjectLyrics3Image) == false) {
            return false;
        }

        ObjectLyrics3Image object = (ObjectLyrics3Image) obj;

        if (this.description.equals(object.description) == false) {
            return false;
        }

        if (this.filename.equals(object.filename) == false) {
            return false;
        }

        if (this.time == null) {
            if (object.time != null) {
                return false;
            }
        } else {
            if (this.time.equals(object.time) == false) {
                return false;
            }
        }

        return super.equals(obj);
    }

    /**
     * DOCUMENT ME!
     *
     * @param imageString DOCUMENT ME!
     * @param offset DOCUMENT ME!
     *
     * @throws NullPointerException DOCUMENT ME!
     * @throws IndexOutOfBoundsException DOCUMENT ME!
     */
    public void readString(String imageString, int offset) {
        if (imageString == null) {
            throw new NullPointerException("Image string is null");
        }

        if ((offset < 0) || (offset >= imageString.length())) {
            throw new IndexOutOfBoundsException("Offset to image string is out of bounds: offset = " + offset + ", string.length()" + imageString.length());
        }

        if (imageString != null) {
            String timestamp;
            int    delim;

            delim    = imageString.indexOf("||", offset);
            filename = imageString.substring(offset, delim);

            offset      = delim + 2;
            delim       = imageString.indexOf("||", offset);
            description = imageString.substring(offset, delim);

            offset    = delim + 2;
            timestamp = imageString.substring(offset);

            if (timestamp.length() == 7) {
                time = new ObjectLyrics3TimeStamp("Time Stamp");
                time.readString(timestamp);
            }
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String toString() {
        String str;
        str = "filename = " + filename + ", description = " + description;

        if (time != null) {
            str += (", timestamp = " + time.toString());
        }

        return str + "\n";
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String writeString() {
        String str = "";

        if (filename == null) {
            str = "||";
        } else {
            str = filename + "||";
        }

        if (description == null) {
            str += "||";
        } else {
            str += (description + "||");
        }

        if (time != null) {
            str += time.writeString();
        }

        return str;
    }
}